/**
 * 
 */
package cz.cuni.mff.abacs.burglar.visual.play_state;

import java.util.LinkedList;
import java.util.List;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.state.StateBasedGame;

import com.aem.sticky.StickyListener;
import com.aem.sticky.button.SimpleButton;
import com.aem.sticky.button.TwoStateButton;
import com.aem.sticky.button.events.SimpleClickListener;

import cz.cuni.mff.abacs.burglar.logics.objects.BaseObject;
import cz.cuni.mff.abacs.burglar.logics.objects.items.Inventory;
import cz.cuni.mff.abacs.burglar.logics.objects.items.Item;
import cz.cuni.mff.abacs.burglar.logics.objects.positions.Active;
import cz.cuni.mff.abacs.burglar.logics.objects.positions.Lockable;
import cz.cuni.mff.abacs.burglar.logics.objects.positions.Vender;
import cz.cuni.mff.abacs.burglar.logics.storage.XMLBase;
import cz.cuni.mff.abacs.burglar.visual.Main;



/**
 * Contains the user interface of the gameplay - buttons, 
 * keyboard and mouse input.
 * 
 * @author abacs
 *
 */
public abstract class InterfacedPlayState extends PlayState {
	
	
	/** Width of the buttons in pixels */
	public static final int BUTTON_WIDTH  = 100;
	/** Height of the buttons in pixels */
	public static final int BUTTON_HEIGHT = 21;
	/**  */
	public static final String STR_INVALID_GAME_MAP = "INVALID GAME MAP";
	
	/**  */
	private StickyListener _buttonListener = null;
	
	private ButtonPanel _buttonPanel = new ButtonPanel(this);
	
	private ContextMenu _contextMenu = new ContextMenu(this);
	
	
	/** if negative, draws all burglar intents */
	protected int _intentDistance = -1;
	
	protected boolean _drawGuardIntents = false;
	
	
	
	// -------------------------------------------------------------------------
	// Constructors:
	
	
	/** 
	 * 
	 * 
	 * @param stateID
	 * @throws SlickExpception
	 */
	protected InterfacedPlayState(int stateID)
			throws SlickException {
		super(stateID);
	}
	
	
	// -------------------------------------------------------------------------
	// state methods:
	
	
	@Override
	public void init(GameContainer container, StateBasedGame game) 
		throws SlickException {
		super.init(container, game);
		
		// create the buttons if not yet initiated:
		if(this._buttonListener == null){
			// set up the buttons:
			this._buttonListener = new StickyListener();
			container.getInput().addListener(this._buttonListener);
	
			Sound buttonSound = 
				new Sound(Main.RESOURCE_PATH + "sound/click.ogg");
			// buttons:
			
			this._buttonPanel.init(container, this._buttonListener, buttonSound);
			
			this._contextMenu.init(container, this._buttonListener, buttonSound);
		}
		// calculate drawing canvas size:
		this._screen._height = 
			(container.getHeight() - 3 * BUTTON_HEIGHT) / 
			Main.RESOURCE_BLOCK_SIZE;
	}
	
	
	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
		throws SlickException {
		// buttons:
		this._buttonPanel.update(container, delta);
		
		this._contextMenu.update(container, delta);

		super.update(container, game, delta);
	}
	
	
	/**
	 *  Allows to draw the world.
	 *  
	 *  @param container
	 *  @param game
	 *  @param graphics
	 *  @throws SlickException
	 *  */
	@Override
	public void render(
			GameContainer container,
			StateBasedGame game,
			Graphics graphics
	) throws SlickException {
		// buttons:		
		this._buttonPanel.render(container, graphics);
		
		this._contextMenu.render(container, graphics);
		
		// HUD:
		this.drawHUD(container, graphics);
	}
	
	
	// -------------------------------------------------------------------------
	
	
	/**
	 * 
	 * 
	 * @param container
	 * @param graphics
	 */
	private void drawHUD(GameContainer container, Graphics graphics) {
		if(this._map == null)
			return;
		
		graphics.setColor(org.newdawn.slick.Color.red);
		
		graphics.drawLine(0,
						  container.getHeight() - 3 * BUTTON_HEIGHT,
						  container.getWidth(),
						  container.getHeight() - 3 * BUTTON_HEIGHT);
		
		StringBuilder hud = new StringBuilder();
		
		hud.append("[");
		hud.append(this._mapState.toString());
		hud.append(", ");
		hud.append(this._runingState.toString());
		hud.append("] | ");
		
		hud.append("[ traps: ");
		hud.append(this._trapsAvioded);
		hud.append(" / ");
		hud.append(this._map.getRequiredTrapRoomCount());
		hud.append("] " );
		
		hud.append("[");
		hud.append(this._selection.getX());
		hud.append(", ");
		hud.append(this._selection.getY());
		hud.append("] ");
		
		try{		
			List<BaseObject> objects = 
				this._map.getObjectsOnPosition(
						this._selection.getX(),
						this._selection.getY()
				);
			for(BaseObject object : objects){
				
				hud.append(XMLBase.typeToString(object.getType()));
				hud.append("(");
				hud.append(object.getId());
				hud.append(") | ");
				
				switch(object.getType()){
				case BURGLAR:
				case CONTAINER:
					hud.append(
							generateHUDItemObjects(
									((Inventory)object).getItems()
							)
					);
					break;
				default:
					
				}
				
			}
			
		}catch(Exception e){
			// game map is invalid
			System.err.println(e.toString());
			hud.append(STR_INVALID_GAME_MAP);
		}
		
		// draw it:
		graphics.drawString(
				hud.toString(),
				5,
				container.getHeight() - 20
		);
		graphics.setColor(org.newdawn.slick.Color.white);
	}
	
	
	/**
	 * Generates a string of information about selected items.
	 * 
	 * @param itemsToDisplay objects to display information about.
	 * @return result string to display.
	 */
	private static String generateHUDItemObjects(List<Item> itemsToDisplay) {
		StringBuilder ret = new StringBuilder();
		for(Item item : itemsToDisplay){
			switch(item.getType()){
			case TREASURE:
				ret.append(XMLBase.STR_TREASURE);
				break;
			case LADDER:
				ret.append(XMLBase.STR_LADDER);
				break;
			case KEY:
				ret.append(XMLBase.STR_KEY);
				break;
			}
			ret.append('(');
			ret.append(item.getId());
			ret.append("), ");
		}
		return ret.toString();
	}
	
	
	// =========================================================================
	
	@Override
	public void mouseMoved(int oldX, int oldY, int newX, int newY){
		// if a context menu is opened, block the selection change.
		if(this._contextMenu.isVisible() == false)
			super.mouseMoved(oldX, oldY, newX, newY);
	}
		
	@Override 
	public void mouseClicked(int button, int x, int y, int clickCount) {
		super.mouseClicked(button, x, y, clickCount);
		
		// 0 - left
		// 1 - right
		// 2 - middle
		
		if(button == 0 && _contextMenu.isVisible() == false){
			this._contextMenu.show(x, y);
		}
	}
	
	
	@Override
	public void pauseUnpause() {
		super.pauseUnpause();
		if(this._runingState == runingState.PAUSED)
			this._buttonPanel._pauseButton.setStateB();
		else
			this._buttonPanel._pauseButton.setStateA();
	}
	
	
	public void increaseIntentDistance() {
		this._intentDistance++;
	}
	
	
	public void decreaseIntentDistance() {
		if(this._intentDistance > 0)
			this._intentDistance--;
	}
	
	
//	public void showHideGuardIntent() {
//		this._drawGuardIntents = ! this._drawGuardIntents;
//	}
	
	
	// -------------------------------------------------------------------------
	
	
	/**
	 * 
	 */
	class ContextMenu {
		
		private InterfacedPlayState _parent;
		
		private boolean _isVisible = false;
		
		private TwoStateButton _closeButton = null;
		private TwoStateButton _lockButton = null;
		private TwoStateButton _activateButton = null;
		private TwoStateButton _cancelButton = null;
		
		private List<TwoStateButton> _buttons = 
			new LinkedList<TwoStateButton>();
		
		
		// ---------------------------------------------------------------------
		
		
		protected ContextMenu(InterfacedPlayState parent) {
			this._parent = parent;
		}
		
		
		// ---------------------------------------------------------------------
		
		
		public void init(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
		
			this.createActivateButton(container, listener, buttonSound);
			this.createCloseButton(container, listener, buttonSound);
			this.createLockButton(container, listener, buttonSound);
			this.createCancelButton(container, listener, buttonSound);
		}
			
		
		public void update(GameContainer container, int delta
		) throws SlickException {
		
			// buttons:
			this._activateButton.update(container, delta);
			this._lockButton.update(container, delta);
			this._closeButton.update(container, delta);
			this._cancelButton.update(container, delta);
			
		}
	
		public void render(
			GameContainer container,
			Graphics graphics
		) throws SlickException {
			// buttons:		
			this._activateButton.render(container, graphics);
			this._lockButton.render(container, graphics);
			this._closeButton.render(container, graphics);
			this._cancelButton.render(container, graphics);
		}
		
		
		// ---------------------------------------------------------------------
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createActivateButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image imgA = new Image(Main.BUTTON_PATH + "activate.png");
			Image imgAHover = new Image(Main.BUTTON_PATH + "activate_hover.png");
			Image imgB = new Image(Main.BUTTON_PATH + "deactivate.png");
			Image imgBHover = new Image(Main.BUTTON_PATH + "deactivate_hover.png");
			
			float x = - BUTTON_WIDTH;
			float y = - BUTTON_HEIGHT;
			this._activateButton = new TwoStateButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					imgA, imgAHover,
					imgB, imgBHover,
					buttonSound
			);
			listener.add(this._activateButton);
			
			this._activateButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.activateDeactivateSelection();
					hide();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createCloseButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image imgA = new Image(Main.BUTTON_PATH + "close.png");
			Image imgAHover = new Image(Main.BUTTON_PATH + "close_hover.png");
			Image imgB = new Image(Main.BUTTON_PATH + "open.png");
			Image imgBHover = new Image(Main.BUTTON_PATH + "open_hover.png");
			
			float x = - BUTTON_WIDTH;
			float y = - BUTTON_HEIGHT;
			this._closeButton = new TwoStateButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					imgA, imgAHover,
					imgB, imgBHover,
					buttonSound
			);
			listener.add(this._closeButton);
			
			this._closeButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.openCloseSelection();
					hide();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createLockButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image imgA = new Image(Main.BUTTON_PATH + "lock.png");
			Image imgAHover = new Image(Main.BUTTON_PATH + "lock_hover.png");
			Image imgB = new Image(Main.BUTTON_PATH + "unlock.png");
			Image imgBHover = new Image(Main.BUTTON_PATH + "unlock_hover.png");
			
			float x = - BUTTON_WIDTH;
			float y = - BUTTON_HEIGHT;
			this._lockButton = new TwoStateButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					imgA, imgAHover,
					imgB, imgBHover,
					buttonSound
			);
			listener.add(this._lockButton);
			
			this._lockButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.lockUnlockSelection();
					hide();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createCancelButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image imgA = new Image(Main.BUTTON_PATH + "cancel.png");
			Image imgAHover = new Image(Main.BUTTON_PATH + "cancel_hover.png");
			
			float x = - BUTTON_WIDTH;
			float y = - BUTTON_HEIGHT;
			this._cancelButton = new TwoStateButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					imgA, imgAHover,
					imgA, imgAHover,
					buttonSound
			);
			listener.add(this._cancelButton);
			
			this._cancelButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					hide();
				}
			});
		}
	
		
		// ---------------------------------------------------------------------
		
		
		private void show(float screenX, float screenY) {
			int mapX = this._parent._selection.getX();
			int mapY = this._parent._selection.getY();
			
			// hide the old context menu:
			this.hide();
			
			try{
				List<BaseObject> objects = 
					this._parent._map.getObjectsOnPosition(mapX, mapY);
				for(BaseObject object : objects){
					switch(object.getType()){
					case CONTAINER:
					case DOOR:
						Lockable lockable = (Lockable)object;
						if(lockable.isClosed()){
							// it can be opened, locked, or unlocked:
							if(lockable.isLocked()){
								// it can be only unlocked:
								this._lockButton.setStateB();
								this._buttons.add(this._lockButton);
							}else{
								// it can be locked, or opened:
								this._lockButton.setStateA();
								this._buttons.add(this._lockButton);
								this._closeButton.setStateB();
								this._buttons.add(this._closeButton);
							}
						}else{
							// it can be closed:
							this._closeButton.setStateA();
							this._buttons.add(this._closeButton);
						}
						break;
					case CAMERA:
					case PHONE:
					case SWITCH:
						if(((Active)object).isActive())
							this._activateButton.setStateB();
						else
							this._activateButton.setStateA();
						this._buttons.add(this._activateButton);
						break;
					case VENDER:
						if(((Vender)object).hasDropped() == false)
							this._activateButton.setStateA();
						this._buttons.add(this._activateButton);
						break;
					default:
					}
				}
			}catch(Exception e){
				System.err.println(e.toString());
			}
			
			
			// add an exit button if there are any other buttons already
			if(this._buttons.size() > 0)
				this._buttons.add(this._cancelButton);
			else
				return;
			
			int deltaX = 0;
			int deltaY = 0;
			
			// if the menu does not fit to the screen,
			// place it to the opposite side.
			
			int screenCornerX = 
				this._parent._screen.mapXToScreenX(this._parent._screen.getWidth());
			int screenCornerY = 
				this._parent._screen.mapYToScreenY(this._parent._screen.getHeight());
			
			if(screenX > screenCornerX - BUTTON_WIDTH)
				deltaX = - BUTTON_WIDTH;
			if(screenY > screenCornerY - BUTTON_HEIGHT * this._buttons.size())
				deltaY = - BUTTON_HEIGHT * this._buttons.size();
			
			for(TwoStateButton button : this._buttons){
				button.moveTo(screenX + deltaX, screenY + deltaY);
				deltaY += BUTTON_HEIGHT;
			}
			
			this._isVisible = true;
		}
		
		
		private void hide() {
			for(TwoStateButton button : this._buttons)
				button.hide();
			this._buttons.clear();
			this._isVisible = false;
		}
		
		private boolean isVisible() {
			return this._isVisible;
		}
		
	}
	
	
	/**
	 * Holds the buttons on the lower part of the window.
	 */
	class ButtonPanel {
		
		private InterfacedPlayState _parent;
		
		// buttons:
		private SimpleButton _exitButton = null;
		private SimpleButton _leaveButton = null;
		private SimpleButton _restartButton = null;
		private SimpleButton _slowDownButton = null;
		private SimpleButton _speedUpButton = null;
		
		private SimpleButton _incIntentDistanceButton = null;
		private SimpleButton _decIntentDistanceButton = null;
		
		//protected TwoStateButton _showGuardIntentsButton = null;
		
		protected TwoStateButton _pauseButton = null;
		
		
		// ---------------------------------------------------------------------
		
		
		protected ButtonPanel(InterfacedPlayState parent) {
			this._parent = parent;
		}
		
		
		// ---------------------------------------------------------------------
		
		
		public void init(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			
			this.createExitButton(container, listener, buttonSound);
			this.createLeaveButton(container, listener, buttonSound);
			this.createRestartButton(container, listener, buttonSound);
			this.createSlowDownButton(container, listener, buttonSound);
			this.createSpeedUpButton(container, listener, buttonSound);
			
			this.createPauseButton(container, listener, buttonSound);
			
			this.createIncIntentDistanceButton(container, listener, buttonSound);
			this.createDecIntentDistanceButton(container, listener, buttonSound);
			//this.createShowGuardIntentsButton(container, listener, buttonSound);
		}
		
		public void update(GameContainer container, int delta)
			throws SlickException {
			
			this._exitButton.update(container, delta);
			this._leaveButton.update(container, delta);
			this._restartButton.update(container, delta);
			this._slowDownButton.update(container, delta);
			this._speedUpButton.update(container, delta);
			this._pauseButton.update(container, delta);
			
			this._incIntentDistanceButton.update(container, delta);
			this._decIntentDistanceButton.update(container, delta);
			//this._showGuardIntentsButton.update(container, delta);
		}
		
		
		/**
		 *  Allows to draw the world.
		 *  */
		public void render(
				GameContainer container,
				Graphics graphics
		) throws SlickException {
			
			this._exitButton.render(container, graphics);
			this._leaveButton.render(container, graphics);
			this._restartButton.render(container, graphics);
			this._slowDownButton.render(container,graphics);
			this._speedUpButton.render(container, graphics);
			this._pauseButton.render(container, graphics);
			
			this._incIntentDistanceButton.render(container, graphics);
			this._decIntentDistanceButton.render(container, graphics);
			//this._showGuardIntentsButton.render(container, graphics);
		}
		
		
		// ---------------------------------------------------------------------
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createExitButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image img = new Image(Main.BUTTON_PATH + "exit.png");
			Image imgHover = new Image(Main.BUTTON_PATH + "exit_hover.png");
			
			float x = container.getWidth() - 1 * BUTTON_WIDTH;
			float y = container.getHeight() - 2 * BUTTON_HEIGHT;
			this._exitButton = new SimpleButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					img, imgHover, buttonSound
			);
			listener.add(this._exitButton);
			
			this._exitButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent._container.exit();
				}	
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createLeaveButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image img = new Image(Main.BUTTON_PATH + "leave.png");
			Image imgHover = new Image(Main.BUTTON_PATH + "leave_hover.png");
			
			float x = container.getWidth() - 1 * BUTTON_WIDTH;
			float y = container.getHeight() - 3 * BUTTON_HEIGHT;
			this._leaveButton = new SimpleButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					img, imgHover, buttonSound
			);
			listener.add(this._leaveButton);
			
			this._leaveButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent._stateBasedGame.enterState(Main.MENU_STATE);
				}
			});	
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createRestartButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image img = new Image(Main.BUTTON_PATH + "restart.png");
			Image imgHover = new Image(Main.BUTTON_PATH + "restart_hover.png");
			
			float x = container.getWidth() - 2 * BUTTON_WIDTH;
			float y = container.getHeight() -  2 * BUTTON_HEIGHT;
			this._restartButton = new SimpleButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					img, imgHover, buttonSound
			);
			listener.add(this._restartButton);
			
			this._restartButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.reload();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createSlowDownButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image img = new Image(Main.BUTTON_PATH + "slow_down.png");
			Image imgHover = new Image(Main.BUTTON_PATH + "slow_down_hover.png");
			
			float x = container.getWidth() - 3 * BUTTON_WIDTH;
			float y = container.getHeight() - 2 * BUTTON_HEIGHT;
			this._slowDownButton = new SimpleButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					img, imgHover, buttonSound
			);
			
			
			listener.add(this._slowDownButton);
			
			this._slowDownButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.decreaseSpeed();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createSpeedUpButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image img = new Image(Main.BUTTON_PATH + "speed_up.png");
			Image imgHover = new Image(Main.BUTTON_PATH + "speed_up_hover.png");
			
			float x = container.getWidth() - 3 * BUTTON_WIDTH;
			float y = container.getHeight() - 3 * BUTTON_HEIGHT;
			this._speedUpButton = new SimpleButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					img, imgHover, buttonSound
			);
			listener.add(this._speedUpButton);
			
			this._speedUpButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.increaseSpeed();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createPauseButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image imgPause = new Image(Main.BUTTON_PATH + "pause.png");
			Image imgPauseHover = new Image(Main.BUTTON_PATH + "pause_hover.png");
			Image imgContinue = new Image(Main.BUTTON_PATH + "continue.png");
			Image imgContinueHover = new Image(Main.BUTTON_PATH + "continue_hover.png");
			
			
			float x = container.getWidth() - 2 * BUTTON_WIDTH;
			float y = container.getHeight() - 3 * BUTTON_HEIGHT;
			this._pauseButton = new TwoStateButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					imgPause, imgPauseHover,
					imgContinue, imgContinueHover,
					buttonSound
			);
			listener.add(this._pauseButton);
			
			this._pauseButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.pauseUnpause();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createIncIntentDistanceButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image img = new Image(Main.BUTTON_PATH + "speed_up.png");
			Image imgHover = new Image(Main.BUTTON_PATH + "speed_up_hover.png");
			
			float x = container.getWidth() - 5 * BUTTON_WIDTH;
			float y = container.getHeight() - 3 * BUTTON_HEIGHT;
			this._incIntentDistanceButton = new SimpleButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					img, imgHover, buttonSound
			);
			listener.add(this._incIntentDistanceButton);
			
			this._incIntentDistanceButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.increaseIntentDistance();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
		private void createDecIntentDistanceButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image img = new Image(Main.BUTTON_PATH + "slow_down.png");
			Image imgHover = new Image(Main.BUTTON_PATH + "slow_down_hover.png");
			
			float x = container.getWidth() - 5 * BUTTON_WIDTH;
			float y = container.getHeight() - 2 * BUTTON_HEIGHT;
			this._decIntentDistanceButton = new SimpleButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					img, imgHover, buttonSound
			);
			listener.add(this._decIntentDistanceButton);
			
			this._decIntentDistanceButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.decreaseIntentDistance();
				}
			});
		}
		
		
		/**
		 * 
		 * 
		 * @param container
		 * @param buttonSound
		 * @throws SlickException
		 */
/*		private void createShowGuardIntentsButton(
				GameContainer container,
				StickyListener listener,
				Sound buttonSound
		) throws SlickException {
			// load the menu images:
			Image imgPause = new Image(Main.BUTTON_PATH + "activate.png");
			Image imgPauseHover = new Image(Main.BUTTON_PATH + "activate_hover.png");
			Image imgContinue = new Image(Main.BUTTON_PATH + "deactivate.png");
			Image imgContinueHover = new Image(Main.BUTTON_PATH + "deactivate_hover.png");
			
			
			float x = container.getWidth() - 4 * BUTTON_WIDTH;
			float y = container.getHeight() - 3 * BUTTON_HEIGHT;
			this._showGuardIntentsButton = new TwoStateButton(
					new Rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT),
					imgPause, imgPauseHover,
					imgContinue, imgContinueHover,
					buttonSound
			);
			listener.add(this._showGuardIntentsButton);
			
			this._showGuardIntentsButton.addListener(new SimpleClickListener() {
				
				@Override
				public void onClick() {
					_parent.showHideGuardIntent();
				}
			});
		}*/
		
		
	}
	
}
